/*
 * Copyright 2020 lcnap
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package pers.lcnap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.lcnap.simplerpc.rpc.NettyServer;
import pers.lcnap.simplerpc.util.BeanContext;

/**
 * 暴露 服务端 接口。
 */
public class RpcServer {

    final Logger logger = LoggerFactory.getLogger(RpcServer.class);

    private NettyServer server;

    public RpcServer() {
        this.server = new NettyServer();
    }

    public RpcServer(int port){
        this.server = new NettyServer(port);
    }

    /**
     * 加载服务实现。
     *
     * @param service 服务实现类
     * @throws Exception
     */
    public void mount(Class<?>... service) throws Exception {
        for (Class<?> clazz : service) {
            BeanContext.putServiceImpl(clazz);
        }
        logger.info("load service [{}]", service);
    }

    public void run() {
        server.run();
    }

    public void shutdown() {
        server.shutdown();
    }
}
